
import Row from "../../qbasics/basics/Row";
import Block from "../../qbasics/basics/Block";
import StrTo from "../../qbasics/utils/StrTo";
export default class Word{

    constructor(core){
        this.core=core;
    }

    /**
     *
     * @param type  0 ，字符串转成数组
     *               1，数组转字符串
     * @param obj
     */
    run(obj,type){

        if(!type){

            let wordIds=[]
            let srts=obj.split("");
            for(let i=0;i<srts.length;i++){
                let num= StrTo.utf8ToNum(srts[i]);
                let wordId =this.addWord(num);
                wordIds.push(wordId)
            }
            return wordIds
        }

        return "";


    }


    /**
     * 通过 字查找 squareId
     */
    findblockIdByWord(roundId,blockId,rowId,dataThis){
        let word=this.word;
            for(let l=0;l<dataThis.list.length;l++){
                let row=dataThis.list[l];
                if(row.isValue(1,word) && row.isValue(4,1)){
                    return l;
                }
            }
        return null;
    }

    /**
     * 添加字   的关键 2
     */
    addWord(word){
        // 查找 代表字的意思
        //如果没有 添加
        this.word=word;
        let squareId = this.core.wordr.findData(0,0,null,this.findblockIdByWord.bind(this))
        if(squareId===null){
            squareId=  this.core.wordr.addData(new Row( word,1),new Block());

        }
        return squareId;

    }
    /**
     /**
     *  查找意 根据 多个字的id
     */
    findIdeaByWordIds(roundId,blockId,rowId,dataThis){


        let wordIds=this.wordIds;
        for(let n=0;n<dataThis.list.length;n++){
            let square=  dataThis.list[i];
            let resis=[];
            for(let l=0;l<square.list.length;l++){
                let row=square[l];
                if(row.isValue(1,wordIds[l]) && row.isValue(4,2)){
                    resis.push( i);
                }
            }
            if(resis.length==wordIds.length){
                return i;
            }
        }
    }




}